package com.medical_houduan.controller;

import com.medical_houduan.commons.Result;
import com.medical_houduan.dto.CityDto;
import com.medical_houduan.service.CityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/city")
@Tag(name = "城市接口",description = "这个接口用于城市查询等操作")
public class CityController {
    @Autowired
    CityService cityService;

    @GetMapping("/getAllCity")
    @Operation(summary = "获取城市数据",description = "获取数据库所有的城市信息，关键字可选，若有关键字则查询包含关键字的所有城市信息(PageInfo)")
    public Result getAllCity(@RequestParam(value = "key",required = false) String keyword,
                             @RequestParam(value = "currentPage",defaultValue = "1",required = false) Integer currentPage,
                             @RequestParam(value = "pageSize",defaultValue = "10",required = false) Integer pageSize){
        return cityService.getCityInfoService(keyword,currentPage,pageSize);
    }

    @PostMapping("/addCity")
    @Operation(summary = "添加城市数据",description = "先根据cityDto对象中的cityNumber获取数据库是否存在该城市信息，没有，则添加城市信息")
    public Result addCity(@RequestBody CityDto cityDto){
        return cityService.addCityService(cityDto);
    }
    @GetMapping("/deleteCity/{cid}")
    @Operation(summary = "删除城市数据",description = "删除该城市信息，并删除该城市下的医保政策")
    public Result deleteCity(@PathVariable("cid")Long cityId){
        return cityService.deleteCityService(cityId);
    }
    @GetMapping("/{cid}")
    @Operation(summary = "cityId查询城市数据",description = "通过cityId查询城市数据")
    public Result findCity(@PathVariable("cid")Long cityId){
        return cityService.findCityService(cityId);
    }
}
